<?php
namespace app\hongyanche\controller;
class MarketingAdmin{
    function swiper_list(){
        //rank格式
        return json(model('swiper')->get_list_admin());
    }
    function swiper_list_inactive(){
        //rank格式
        return json(model('swiper')->get_list_inactive());
    }
    function swiper_add(){
        $url 		= input('url');
        return json(model('swiper')->add($url));
    }
    function swiper_range(){
        $range 		= input('range'); // [235,4345,2,23,5]
        return json(model('swiper')->range($range));
    }
    function swiper_remove(){
        $swiper_id 	= input('swiper_id');
        return json(model('swiper')->remove($swiper_id));
    }
    function swiper_remove_all(){
        return json(model('swiper')->remove_all());
    }
    function swiper_release(){
        $swiper_id 	= input('swiper_id');
        $release 	= (boolean)input('release');
        return json(model('swiper')->release($swiper_id,$release));
    }
    function swiper_modify(){
        $swiper_id 	= input('swiper_id');
        $modify 	= input('modify');
        return json(model('swiper')->modify($swiper_id,$modify));
    }


    //广告位管理
    public function ad_list(){
        $res = model('ad')->ad_list();
        return json($res);
    }
    function ad_add(){
        $imgurl = input('imgurl');
        $place = input('place');
        $home_url = input('home_url');
        return json(model('ad')->ad_add($imgurl,$place,$home_url));
    }

    function ad_remove(){
        $ad_id 	= input('ad_id');
        return json(model('ad')->ad_remove($ad_id));
    }
    function ad_release(){
        $ad_id 	= input('ad_id');
        $release 	= input('release');
        return json(model('ad')->ad_release($ad_id,$release));
    }

    //视频上传
    function video_add()
    {
        ini_set("max_execution_time", 0);
        $z = input('z');
        $res = model('video')->add($z);
        return json($res);
    }
    function video_modify(){
        $id = input('video_id');
        $key = input('key');
        $content = input('content');
        $res = model('video')->modify($id,$key,$content);
        return json($res);
    }
    function video_remove(){
        $id = input('video_id');
        $res = model('video')->remove($id);
        return json($res);
    }
    function video_list(){
        $list = db('marketing_video')->where("state = 1")->select();
        if(!$list) return ['state'=>1,'data'=>[]];
        return ['state'=>1,'data'=>['list'=>$list]];
    }

    //表情上传
    public function expression_list(){
        if(!model('admin')->is('forum',1)['state']) return ['state'=>0,'errormsg'=>'您没有权限'];
        $res = model('expression')->getlist();
        return json($res);
    }
    function expression_add(){
        if(!model('admin')->is('forum',1)['state']) return ['state'=>0,'errormsg'=>'您没有权限'];
        $imgurl = input('url');
        return json(model('expression')->add($imgurl));
    }

    function expression_remove(){
        if(!model('admin')->is('forum',1)['state']) return ['state'=>0,'errormsg'=>'您没有权限'];
        $expression_id 	= input('expression_id');
        return json(model('expression')->remove($expression_id));
    }
    function expression_release(){
        if(!model('admin')->is('forum',1)['state']) return ['state'=>0,'errormsg'=>'您没有权限'];
        $expression_id 	= input('expression_id');
        $release 	= input('release');
        return json(model('expression')->release($expression_id,$release));
    }
    //设置等级
    public function setlevel()
    {
        if(!model('admin')->is('forum',1)['state']) return ['state'=>0,'errormsg'=>'您没有权限'];
        $level = input('level');
        $res = model('expression')->setlevel($level);
        return json($res);
    }
}